/**
 * Zhe Jiang HongCheng System Inc.
 * Copyright All Rights Reserved.
 */
package com.zjhcsoft.jbosscache.util;

import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * FileName : ApplicationStartupListener.java
 * CreateTime : 11-11-10 下午8:22
 * Description : 应用程序启动监听器
 *
 * @author : liuys
 * @version : 1.0
 */
public class ApplicationStartupListener implements ServletContextListener {
    private static final Logger logger = LoggerFactory.getLogger(ApplicationStartupListener.class);

    public void contextInitialized(ServletContextEvent sce) {
        CacheFactory<String, Object> factory = new DefaultCacheFactory<String, Object>();
        Cache<String, Object> cache = factory.createCache("demo-cache-config.xml");
        logger.debug("JbossCache | Application Startup.");
        cache.create();
        cache.start();
        WebContextHolder.getInstance().setJbossCache(cache);
        //后面可加载系统初始化数据
    }

    public void contextDestroyed(ServletContextEvent sce) {
        WebContextHolder.clearHolder();
    }
}
